using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using System.Drawing;
using GuavaData;

namespace GuavaLib
{
    public partial class GPanel: Panel, Guava
    {
        string gname;
        Label lab;
        public GPanel()
        {
            InitializeComponent();
        }

        public GPanel(IContainer container)
          {
              container.Add(this);

              InitializeComponent();
          }
        public System.Windows.Forms.Label Label
        {
            get { return lab; }
            set { lab = value; }
        }
        #region Guava Members
        [Browsable(false)]
        public LaunchType LType
        {
            get
            {
                return LaunchType.NA;
            }
        }

        [Browsable(false)]
        public ControlType CType
        {
            get
            {
                return ControlType.Container;
            }
        }

        [Browsable(false)]
        public string GText
        {
            get
            {
                if (this.lab == null) return null;
                return this.lab.Text;
            }
        }

        public string GName
        {
            get
            {
                if (gname == null) return this.Name;
                return gname;
            }
            set
            {
                gname = value;
            }
        }

        [Browsable(false)]
        public Point GLocation
        {
            get { return this.Location; }
        }

        [Browsable(false)]
        public Size GSize
        {
            get { return this.Size; }
        }

        [Browsable(false)]
        public List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();

                foreach (Control c in this.Controls)
                {
                    if (c is Guava) lg.Add((Guava)c);
                }

                return lg;
            }
        }

        public void GBind(string table, int i)
        {
            // Bind all child elements
            foreach (Guava c in GComponents)
            {
                c.GBind(table, i);
            }
        }

        [Browsable(false)]
        public string GDefault
        {
            get { return null; }
        }

        [Browsable(false)]
        public string GToolTip
        {
            get
            {
                Control p = this.TopLevelControl;
                if (!(p is Guava)) return null;
                ToolTip t = (p as GuavaForm).GToolTipProvider;
                if (t == null) return null;

                // Fetch the tooltip and return it
                return t.GetToolTip(this);
            }
        }

        [Browsable(false)]
        public GuavaData.Domain.Domain GDomain
        {
            get
            {
                return null;
            }
        }

        public Guava this[string s]
        {
            get
            {
                foreach (Guava g in this.GComponents) if (g.GName == s) return g;
                return null;
            }
        }
        #endregion
      
    }
}
